package com.hh.controller;

import com.hh.service.ClientService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.charset.StandardCharsets;

@RestController
public class DeviceController {
    Logger logger = LoggerFactory.getLogger(getClass());
    @Resource
    private ClientService clientService;
    /**
     * 向服务器发送消息
     */
    @PostMapping("/sendMessage")
    public void sendMessage(String message){
        logger.info("-----open_method6--------" + message);
        AsynchronousSocketChannel channel = clientService.getChannel();
        channel.write(ByteBuffer.wrap(message.getBytes(StandardCharsets.UTF_8)));//往服务端发送控制命令数据
    }
}